Add splitAt#179
Conversation
1b9ca0a to
e3268cf
Compare
| assert $ A.splitAt 4 [1, 2, 3] == Tuple [1, 2, 3] [] | ||
| assert $ A.splitAt 0 [1, 2, 3] == Tuple [] [1, 2, 3] | ||
| assert $ A.splitAt (-1) [1, 2, 3] == Tuple [] [1, 2, 3] | ||
|
|
There was a problem hiding this comment.
There should be a test here for when the array argument is empty. I assume splitAt n [] produces Tuple [] [].
There was a problem hiding this comment.
Added in 6f414d6:
assert $ A.splitAt 2 ([] :: Array Int) == { before: [], after: [] }| -- | | ||
| -- | ```purescript | ||
| -- | splitAt 3 [1, 2, 3, 4, 5] == Tuple [1, 2, 3] [4, 5] | ||
| -- | ``` |
There was a problem hiding this comment.
Docs should specify what happens when an empty array is the argument
There was a problem hiding this comment.
Added in 6f414d6:
-- | splitAt 2 ([] :: Array Int) == { before: [], after: [] }|
I wonder if we should have this return a record |
|
I'd agree with that. It also removes the need to document which array is the before/after part (though that itself is likely obvious). |
|
Funnily enough, I had initially considered doing this, but was hung up on the It wasn't until just now where I realized that, conceptually, taking |
I see it more like this: let { before, after} = splitAt i array
in
(before == take i array) && (after == drop i array) |
This PR adds a
splitAtfunction forArrays andNonEmptyArrays.Prior Art
Haskell:
splitAtfp-ts:
splitAt